package leetcode;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;

public class Test2017 {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode p = new ListNode(3);
        head.next=p;
        ListNode p1 = new ListNode(2);
        p.next=p1;
        Test2017 test2017 = new Test2017();
        Arrays.stream(test2017.reversePrint(head)).forEach(System.out::println);


    }
    public int[] reversePrint(ListNode head) {
        Deque<Integer> integers = new ArrayDeque<>();
        while (head.next != null) {
            integers.push(head.val);
            head=head.next;
        }

        integers.push(head.val);
        int[] ans = new int[integers.size()];
        int j=0;
        while(!integers.isEmpty()){
            ans[j]=integers.pop();
            j++;
        }
        return ans;
    }
}


//Definition for singly-linked list.
@Data
@AllArgsConstructor
@NoArgsConstructor
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}
